package operations;

import book.Book;
import book.Booklist;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class DelOperation implements IOperation{
    public void work (Booklist booklist){
        //删除图书
        System.out.println("删除图书！");
        System.out.println("请输入要删除的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int ret = -1;
        for (int i = 0; i < booklist.getUsedSize(); i++) {
            if(name.equals(booklist.getBooks()[i].getName())){
                ret = i;
            }
        }
        for (int i = ret; i < booklist.getUsedSize() - 1; i++) {
            booklist.setBooks(booklist.getBooks()[i + 1], i);
        }
        booklist.setBooks(null, booklist.getUsedSize() - 1);
        if(ret == -1){
            System.out.println("没有这本书！");
        }else{
            System.out.println("删除成功！");
            booklist.setUsedSize(booklist.getUsedSize() - 1);
        }
    }
}
